package com.biomatch.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.biomatch.domain.ContainerLock;
import com.biomatch.dto.ContainerLockPagination;
import com.biomatch.dto.Pagination;
import com.biomatch.response.RestResponse;
import com.biomatch.response.RestResult;
import com.biomatch.service.ContainerLockService;
import com.biomatch.utils.Internationalize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RestController("lock.containerLock")
@RequestMapping("/containerLock")
@Api(value="液氮罐锁管理")
public class ContainerLockController {
    @Autowired
    private ContainerLockService containerLockService;

    @Autowired
    private Internationalize internationalize;

    @RequestMapping(value="/getContainerLockList", method = RequestMethod.POST)
    @ApiOperation(value = "获得液氮罐锁信息", response = ContainerLock.class, httpMethod = "POST")
    public RestResult<List<ContainerLock>> getContainerLockList() {
        List<ContainerLock> containerLockList = containerLockService.getContainerLockList();
        return RestResponse.success(containerLockList);
    }


    @RequestMapping(value="/getContainerLockAndGroupAndRule", method = RequestMethod.POST)
    @ApiOperation(value = "分页获得液氮罐锁和组合规则和位置信息", response = ContainerLock.class, httpMethod = "POST")
    public RestResult<ContainerLock> getContainerLockAndGroupAndRule(@RequestBody ContainerLockPagination pagination) {
         IPage<ContainerLock> result=containerLockService.getContainerLockAndGroupAndRule(pagination);
        return RestResponse.success(result);
    }


    @RequestMapping(value="/saveOrUpdateContainerLock", method = RequestMethod.POST)
    @ApiOperation(value = "添加或修改液氮罐锁所有信息", response = ContainerLock.class, httpMethod = "POST")
    public RestResult<ContainerLock> updateUser(@RequestBody ContainerLock containerLock) {
        ContainerLock result = containerLockService.saveOrUpdateContainerLock(containerLock);
        if (result == null)
        {
            return RestResponse.error(internationalize.getMessage("containerLock.name.repeat"));
        } else {
            return RestResponse.success(result);
        }
    }

    @RequestMapping(value="/delContainerLockById", method = RequestMethod.POST)
    @ApiOperation(value = "删除液氮罐锁信息", response = ContainerLock.class, httpMethod = "POST")
    public RestResult<ContainerLock> delContainerLockById(@RequestBody ContainerLock containerLock) {
        ContainerLock  result=containerLockService.delContainerLockById(containerLock);
        return RestResponse.success(result);
    }

}
